/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytools;

import java.sql.*;
import java.util.*;

/**
 *
 * @author xiaoxiao
 */
public class examDAO {

    private Connection con;

    public examDAO() throws Exception {
    }
    //获取所有的科目

    public List<String> getallsubject() throws Exception {
        con = dbcon.getConnection();
        List<String> list = new ArrayList<String>();
        HashSet<String> set = new HashSet();
        PreparedStatement ps = con.prepareStatement("select distinct subject from choiceques");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            set.add(rs.getString("subject"));
        }

        ps = con.prepareStatement("select distinct subject from judgeques");
        rs = ps.executeQuery();
        while (rs.next()) {
            set.add(rs.getString("subject"));
        }

        ps = con.prepareStatement("select distinct subject from subjectiveques");
        rs = ps.executeQuery();
        while (rs.next()) {
            set.add(rs.getString("subject"));
        }
        rs.close();
        con.close();

        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            list.add(it.next());
        }
        Collections.sort(list);
        return list;
    }
    //获取所有的章节

    public List<String> getallchapter() throws Exception {
        con = dbcon.getConnection();
        List<String> list = new ArrayList<String>();
        HashSet<String> set = new HashSet();
        PreparedStatement ps = con.prepareStatement("select distinct chapter from choiceques");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            set.add(rs.getString("chapter"));
        }

        ps = con.prepareStatement("select distinct chapter from judgeques");
        rs = ps.executeQuery();
        while (rs.next()) {
            set.add(rs.getString("chapter"));
        }

        ps = con.prepareStatement("select distinct chapter from subjectiveques");
        rs = ps.executeQuery();
        while (rs.next()) {
            set.add(rs.getString("chapter"));
        }
        rs.close();
        con.close();

        Iterator<String> it = set.iterator();
        while (it.hasNext()) {
            list.add(it.next());
        }
        Collections.sort(list);
        return list;
    }
    /*获取对应科目的单选题的ID号数组*/

    public int[] getdanxuansujectid(String subject) throws Exception {
        int array[] = new int[this.getdanxuanAmount(subject)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from choiceques where type='单选题' and subject='" + subject + "'");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }
    /*获取对应科目、章节的单选题的ID号数组*/

    public int[] getdanxuansujectchapterid(String subject, String chapter) throws Exception {
        int array[] = new int[this.getdanxuanAmount(subject, chapter)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from choiceques where type='单选题' and subject='" + subject + "' and chapter in(" + chapter + ")");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }
    /*获取对应科目的多选题的ID号数组*/

    public int[] getduoxuansujectid(String subject) throws Exception {
        int array[] = new int[this.getduoxuanAmount(subject)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from choiceques where type='多选题' and subject='" + subject + "'");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }
    /*获取对应科目、章节的多选题的ID号数组*/

    public int[] getduoxuansujectchapterid(String subject, String chapter) throws Exception {
        int array[] = new int[this.getduoxuanAmount(subject, chapter)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from choiceques where type='多选题' and subject='" + subject + "' and chapter in(" + chapter + ")");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }
    /*获取对应科目的判断题的ID号数组*/

    public int[] getjudgesujectid(String subject) throws Exception {
        int array[] = new int[this.getjudgeAmount(subject)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from judgeques where subject='" + subject + "'");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }
    /*获取对应科目、章节的判断题的ID号数组*/

    public int[] getjudgesujectchapterid(String subject, String chapter) throws Exception {
        int array[] = new int[this.getjudgeAmount(subject, chapter)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from judgeques where subject='" + subject + "' and chapter in(" + chapter + ")");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }

    public int[] getquestionsujectid(String subject) throws Exception {
        int array[] = new int[this.getquestionAmount(subject)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from subjectiveques where subject='" + subject + "'");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }

    public int[] getquestionsujectchapterid(String subject, String chapter) throws Exception {
        int array[] = new int[this.getquestionAmount(subject, chapter)];
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select id from subjectiveques where subject='" + subject + "' and chapter in(" + chapter + ")");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            array[i++] = rs.getInt("id");
        }
        con.close();
        return array;
    }
    /*获取对应科目的单选题的数目*/

    public int getdanxuanAmount(String str) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select count(*) from choiceques where type='单选题' and subject='" + str + "'");
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }
    /*获取对应科目、章节的单选题的数目*/

    public int getdanxuanAmount(String subject, String chapter) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        PreparedStatement ps = null;
        ps = con.prepareStatement("select count(*) from choiceques where type='单选题' and subject='" + subject + "' and chapter in(" + chapter + ")");
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getduoxuanAmount(String str) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from choiceques where type='多选题' and subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getduoxuanAmount(String subject, String chapter) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from choiceques where type='多选题' and subject='" + subject + "' and chapter in(" + chapter + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getjudgeAmount(String str) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from judgeques where subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getjudgeAmount(String subject, String chapter) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from judgeques where subject='" + subject + "' and chapter in(" + chapter + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getquestionAmount(String str) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from subjectiveques where subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getquestionAmount(String subject, String chapter) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from subjectiveques where subject='" + subject + "' and chapter in(" + chapter + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int addexam(exam exam) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "insert into exam (eid,name,descript,creattime,userid) values(null,?,?,?,?)";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ps.setString(1, exam.getName());
        ps.setString(2, exam.getDescript());
        ps.setString(3, exam.getCreattime());
        ps.setInt(4, exam.getUserid());
        i = ps.executeUpdate();
        ps.close();
        con.close();
        return i;
    }

    public int editexam(exam exam) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "update exam set name=?,descript=? where eid=?";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1, exam.getName());
        ps.setString(2, exam.getDescript());
        ps.setInt(3, exam.getEid());
        i = ps.executeUpdate();
        ps.close();
        con.close();
        return i;
    }

    public int deleteexam(int id) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        Statement st = con.createStatement();
        i = st.executeUpdate("delete from exam where eid='" + id + "'");
        con.close();
        return i;
    }

    public int updateej(String result, int eid) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "update exam set ej=? where eid=?";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ps.setString(1, result);
        ps.setInt(2, eid);
        i = ps.executeUpdate();
        con.close();
        return i;
    }

    public int updateec(String result, int eid) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "update exam set ec=? where eid=?";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ps.setString(1, result);
        ps.setInt(2, eid);
        i = ps.executeUpdate();
        con.close();
        return i;

    }

    public int updateeq(String result, int eid) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "update exam set eq=? where eid=?";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ps.setString(1, result);
        ps.setInt(2, eid);
        i = ps.executeUpdate();
        con.close();
        return i;

    }

    public exam getexam(int id) throws Exception {
        con = dbcon.getConnection();
        exam exam = null;
        String sql = "select * from exam where eid=?";
        PreparedStatement psmt = null;
        psmt = con.prepareStatement(sql);
        psmt.setInt(1, id);
        ResultSet rs = psmt.executeQuery();
        if (rs.next()) {
            exam = new exam();
            exam.setEid(id);
            exam.setName(rs.getString("name"));
            exam.setDescript(rs.getString("descript"));
            exam.setCreattime(rs.getString("creattime"));
            exam.setEc(rs.getString("ec"));
            exam.setEj(rs.getString("ej"));
            exam.setEq(rs.getString("eq"));
        }
        rs.close();
        psmt.close();
        con.close();
        return exam;
    }

    public int getexamsearchAmount(String search) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from exam where name like('%" + search + "%') or descript like('%" + search + "%') or eid like('%" + search + "%')";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getexamAmount() throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from exam";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }

    public int getselfexamAmount(String userid) throws Exception {
        con = dbcon.getConnection();
        int i = 0;
        String sql = "select count(*) from exam where userid=?";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ps.setString(1, userid);
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            i = rs.getInt(1);
        }
        con.close();
        return i;
    }
    /*获取对应页码的试题信息条目*/

    public List<exam> getsearchexamlist(int pagenumber, int pagesize, String search) throws Exception {
        con = dbcon.getConnection();
        List<exam> list = new ArrayList<exam>();
        String sql = "select * from exam where name like('%" + search + "%') or descript like('%" + search + "%') or eid like('%" + search + "%') limit ?,?";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        if (pagenumber < 1) {
            pagenumber = 1;
        }
        ps.setInt(1, (pagenumber - 1) * pagesize);
        ps.setInt(2, pagesize);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            exam exam = new exam();
            exam.setEid(rs.getInt("eid"));
            exam.setName(rs.getString("name"));
            exam.setDescript(rs.getString("descript"));
            exam.setCreattime(rs.getString("creattime"));
            exam.setEc(rs.getString("ec"));
            exam.setEj(rs.getString("ej"));
            exam.setEq(rs.getString("eq"));
            list.add(exam);
        }
        con.close();
        return list;
    }

    public List<exam> getselfexamlist(int pagenumber, int pagesize, String userid) throws Exception {
        con = dbcon.getConnection();
        List<exam> list = new ArrayList<exam>();
        String sql = "select * from exam where userid=? limit ?,? ";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        if (pagenumber < 1) {
            pagenumber = 1;
        }
        ps.setInt(2, (pagenumber - 1) * pagesize);
        ps.setInt(3, pagesize);
        ps.setString(1, userid);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            exam exam = new exam();
            exam.setEid(rs.getInt("eid"));
            exam.setName(rs.getString("name"));
            exam.setDescript(rs.getString("descript"));
            exam.setCreattime(rs.getString("creattime"));
            exam.setEc(rs.getString("ec"));
            exam.setEj(rs.getString("ej"));
            exam.setEq(rs.getString("eq"));
            list.add(exam);
        }
        con.close();
        return list;
    }

    public List<exam> getexamlist(int pagenumber, int pagesize) throws Exception {
        con = dbcon.getConnection();
        List<exam> list = new ArrayList<exam>();
        String sql = "select * from exam limit ?,?";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        if (pagenumber < 1) {
            pagenumber = 1;
        }
        ps.setInt(1, (pagenumber - 1) * pagesize);
        ps.setInt(2, pagesize);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            exam exam = new exam();
            exam.setEid(rs.getInt("eid"));
            exam.setName(rs.getString("name"));
            exam.setDescript(rs.getString("descript"));
            exam.setCreattime(rs.getString("creattime"));
            exam.setEc(rs.getString("ec"));
            exam.setEj(rs.getString("ej"));
            exam.setEq(rs.getString("eq"));
            list.add(exam);
        }
        con.close();
        return list;
    }

    public List<choice> getdanxuan(String str) throws Exception {
        con = dbcon.getConnection();
        List<choice> list = new ArrayList<choice>();
        String sql = "select * from choiceques where type='单选题'  and id in(" + str + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            choice choice = new choice();
            choice.setId(rs.getInt("id"));
            choice.setName(rs.getString("name"));
            choice.setA(rs.getString("a"));
            choice.setB(rs.getString("b"));
            choice.setC(rs.getString("c"));
            choice.setD(rs.getString("d"));
            choice.setAnswer(rs.getString("answer"));
            choice.setType(rs.getString("type"));
            choice.setLevel(rs.getString("level"));
            choice.setSubject(rs.getString("subject"));
            choice.setChapter(rs.getString("chapter"));
            choice.setChapterinfo(rs.getString("chapterinfo"));
            list.add(choice);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<choice> getdanxuansubject(String str) throws Exception {
        con = dbcon.getConnection();
        List<choice> list = new ArrayList<choice>();
        String sql = "select * from choiceques where type='单选题' and subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            choice choice = new choice();
            choice.setId(rs.getInt("id"));
            choice.setName(rs.getString("name"));
            choice.setA(rs.getString("a"));
            choice.setB(rs.getString("b"));
            choice.setC(rs.getString("c"));
            choice.setD(rs.getString("d"));
            choice.setAnswer(rs.getString("answer"));
            choice.setType(rs.getString("type"));
            choice.setLevel(rs.getString("level"));
            choice.setSubject(rs.getString("subject"));
            choice.setChapter(rs.getString("chapter"));
            choice.setChapterinfo(rs.getString("chapterinfo"));
            list.add(choice);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<choice> getdanxuansubjectchapter(String str, String chapter) throws Exception {
        con = dbcon.getConnection();
        List<choice> list = new ArrayList<choice>();
        String sql = "select * from choiceques where type='单选题' and subject='" + str + "' and chapter in(" + chapter + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            choice choice = new choice();
            choice.setId(rs.getInt("id"));
            choice.setName(rs.getString("name"));
            choice.setA(rs.getString("a"));
            choice.setB(rs.getString("b"));
            choice.setC(rs.getString("c"));
            choice.setD(rs.getString("d"));
            choice.setAnswer(rs.getString("answer"));
            choice.setType(rs.getString("type"));
            choice.setLevel(rs.getString("level"));
            choice.setSubject(rs.getString("subject"));
            choice.setChapter(rs.getString("chapter"));
            choice.setChapterinfo(rs.getString("chapterinfo"));
            list.add(choice);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<choice> getduoxuan(String str) throws Exception {
        con = dbcon.getConnection();
        List<choice> list = new ArrayList<choice>();
        String sql = "select * from choiceques where type='多选题' and id in(" + str + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            choice choice = new choice();
            choice.setId(rs.getInt("id"));
            choice.setName(rs.getString("name"));
            choice.setA(rs.getString("a"));
            choice.setB(rs.getString("b"));
            choice.setC(rs.getString("c"));
            choice.setD(rs.getString("d"));
            choice.setAnswer(rs.getString("answer"));
            choice.setType(rs.getString("type"));
            choice.setLevel(rs.getString("level"));
            choice.setSubject(rs.getString("subject"));
            choice.setChapter(rs.getString("chapter"));
            choice.setChapterinfo(rs.getString("chapterinfo"));
            list.add(choice);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<choice> getduoxuansubject(String str) throws Exception {
        con = dbcon.getConnection();
        List<choice> list = new ArrayList<choice>();
        String sql = "select * from choiceques where type='多选题' and subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            choice choice = new choice();
            choice.setId(rs.getInt("id"));
            choice.setName(rs.getString("name"));
            choice.setA(rs.getString("a"));
            choice.setB(rs.getString("b"));
            choice.setC(rs.getString("c"));
            choice.setD(rs.getString("d"));
            choice.setAnswer(rs.getString("answer"));
            choice.setType(rs.getString("type"));
            choice.setLevel(rs.getString("level"));
            choice.setSubject(rs.getString("subject"));
            choice.setChapter(rs.getString("chapter"));
            choice.setChapterinfo(rs.getString("chapterinfo"));
            list.add(choice);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<choice> getduoxuansubjectchapter(String str, String chapter) throws Exception {
        con = dbcon.getConnection();
        List<choice> list = new ArrayList<choice>();
        String sql = "select * from choiceques where type='多选题' and subject='" + str + "' and chapter in(" + chapter + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            choice choice = new choice();
            choice.setId(rs.getInt("id"));
            choice.setName(rs.getString("name"));
            choice.setA(rs.getString("a"));
            choice.setB(rs.getString("b"));
            choice.setC(rs.getString("c"));
            choice.setD(rs.getString("d"));
            choice.setAnswer(rs.getString("answer"));
            choice.setType(rs.getString("type"));
            choice.setLevel(rs.getString("level"));
            choice.setSubject(rs.getString("subject"));
            choice.setChapter(rs.getString("chapter"));
            choice.setChapterinfo(rs.getString("chapterinfo"));
            list.add(choice);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<judge> getjudge(String str) throws Exception {
        con = dbcon.getConnection();
        List<judge> list = new ArrayList<judge>();
        String sql = "select * from judgeques where id in(" + str + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            judge judge = new judge();
            judge.setId(rs.getInt("id"));
            judge.setName(rs.getString("name"));
            judge.setAnswer(rs.getString("answer"));
            judge.setType(rs.getString("type"));
            judge.setLevel(rs.getString("level"));
            judge.setSubject(rs.getString("subject"));
            judge.setChapter(rs.getString("chapter"));
            judge.setChapterinfo(rs.getString("chapterinfo"));
            list.add(judge);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<judge> getjudgesubject(String str) throws Exception {
        con = dbcon.getConnection();
        List<judge> list = new ArrayList<judge>();
        String sql = "select * from judgeques where subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            judge judge = new judge();
            judge.setId(rs.getInt("id"));
            judge.setName(rs.getString("name"));
            judge.setAnswer(rs.getString("answer"));
            judge.setType(rs.getString("type"));
            judge.setLevel(rs.getString("level"));
            judge.setSubject(rs.getString("subject"));
            judge.setChapter(rs.getString("chapter"));
            judge.setChapterinfo(rs.getString("chapterinfo"));
            list.add(judge);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<judge> getjudgesubjectchapter(String str, String chapter) throws Exception {
        con = dbcon.getConnection();
        List<judge> list = new ArrayList<judge>();
        String sql = "select * from judgeques where chapter in(" + chapter + ") and subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            judge judge = new judge();
            judge.setId(rs.getInt("id"));
            judge.setName(rs.getString("name"));
            judge.setAnswer(rs.getString("answer"));
            judge.setType(rs.getString("type"));
            judge.setLevel(rs.getString("level"));
            judge.setSubject(rs.getString("subject"));
            judge.setChapter(rs.getString("chapter"));
            judge.setChapterinfo(rs.getString("chapterinfo"));
            list.add(judge);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<question> getquestion(String str) throws Exception {
        con = dbcon.getConnection();
        List<question> list = new ArrayList<question>();
        String sql = "select * from subjectiveques where id in(" + str + ")";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            question question = new question();
            question.setId(rs.getInt("id"));
            question.setName(rs.getString("name"));
            question.setAnswer(rs.getString("answer"));
            question.setType(rs.getString("type"));
            question.setLevel(rs.getString("level"));
            question.setSubject(rs.getString("subject"));
            question.setChapter(rs.getString("chapter"));
            question.setChapterinfo(rs.getString("chapterinfo"));
            list.add(question);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<question> getquestionsubject(String str) throws Exception {
        con = dbcon.getConnection();
        List<question> list = new ArrayList<question>();
        String sql = "select * from subjectiveques where subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            question question = new question();
            question.setId(rs.getInt("id"));
            question.setName(rs.getString("name"));
            question.setAnswer(rs.getString("answer"));
            question.setType(rs.getString("type"));
            question.setLevel(rs.getString("level"));
            question.setSubject(rs.getString("subject"));
            question.setChapter(rs.getString("chapter"));
            question.setChapterinfo(rs.getString("chapterinfo"));
            list.add(question);
        }
        rs.close();
        con.close();
        return list;
    }

    public List<question> getquestionsubjectchapter(String str, String chapter) throws Exception {
        con = dbcon.getConnection();
        List<question> list = new ArrayList<question>();
        String sql = "select * from subjectiveques where chapter in(" + chapter + ") and subject='" + str + "'";
        PreparedStatement ps = null;
        ps = con.prepareStatement(sql);
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            question question = new question();
            question.setId(rs.getInt("id"));
            question.setName(rs.getString("name"));
            question.setAnswer(rs.getString("answer"));
            question.setType(rs.getString("type"));
            question.setLevel(rs.getString("level"));
            question.setSubject(rs.getString("subject"));
            question.setChapter(rs.getString("chapter"));
            question.setChapterinfo(rs.getString("chapterinfo"));
            list.add(question);
        }
        rs.close();
        con.close();
        return list;
    }
}
